package org.makcro.sms.services.chat.web.client.widgets;

import org.makcro.sms.services.chat.web.shared.dto.HistoryItemDto;

import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public class DeliveryReportGridCellRendererImpl implements GridCellRenderer<HistoryItemDto> {

	private Template	template				= new Template( "<span style='color:{textColor}'>{value}</span>" );
	private String		deliveredTextColor		= "#0066FF";
	private String		undeliveredTextColor	= "#CC0000";
	private String		deliveredStatusValue	= "Da";
	private String		unDeliveredStatusValue	= "Ne";

	@Override
	public Object render(HistoryItemDto model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<HistoryItemDto> store, Grid<HistoryItemDto> grid) {
		Boolean answerDelivered = model.getAnswerDelivered();
		// set template param values
		Params params = new Params();
		params.set( "textColor", answerDelivered ? deliveredTextColor : undeliveredTextColor );
		params.set( "value", answerDelivered ? deliveredStatusValue: unDeliveredStatusValue);
		String appliedTemplate = template.applyTemplate( params );
		
		return appliedTemplate.toString();
	}

}
